From 7f33a86ead474126cf3273d6b00b863e54ed0808 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Fri, 17 Nov 2006 03:59:32 +0000 Subject: [PATCH] (bug 7688) When viewing diff, section anchors in autosummary jump to section on current page. Patch by Mark Haidar (Fyren) with slight modifications. --- RELEASE-NOTES | 2 ++ includes/DifferenceEngine.php | 2 +- includes/Linker.php | 38 +++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 558b8cfaa3..9ec65700ba 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -198,6 +198,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 7918) "Templates used on this page" changes during preview to reflect any added or removed templates. * (bug 7918) "Templates used on this page" is now shown for read-only pages. +* (bug 7688) When viewing diff, section anchors in autosummary jump to section + on current page. == Languages updated == diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 2bccc8f71a..9adcda571d 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -186,7 +186,7 @@ CONTROL; $prevlink; $newHeader = "{$this->mNewtitle}
" . $sk->revUserTools( $this->mNewRev ) . " $rollback
" . - $newminor . $sk->revComment( $this->mNewRev ) . "
" . + $newminor . $sk->revComment( $this->mNewRev, true ) . "
" . $nextlink . $patrol; $this->showDiff( $oldHeader, $newHeader ); diff --git a/includes/Linker.php b/includes/Linker.php index a1b48ab8de..7be89e6b11 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -881,17 +881,18 @@ class Linker { * comments. It escapes any HTML in the comment, but adds some CSS to format * auto-generated comments (from section editing) and formats [[wikilinks]]. * - * The $title parameter must be a title OBJECT. It is used to generate a - * direct link to the section in the autocomment. * @author Erik Moeller * * Note: there's not always a title to pass to this function. * Since you can't set a default parameter for a reference, I've turned it * temporarily to a value pass. Should be adjusted further. --brion + * + * $param string $comment + * @param Title $title (to generate link to the section in autocomment) + * @param bool $local Whether section links should refer to local page */ - function formatComment($comment, $title = NULL) { - $fname = 'Linker::formatComment'; - wfProfileIn( $fname ); + function formatComment($comment, Title $title = NULL, $local = false) { + wfProfileIn( __METHOD__ ); global $wgContLang; $comment = str_replace( "\n", " ", $comment ); @@ -917,8 +918,12 @@ class Linker { $section = str_replace( '[[:', '', $section ); $section = str_replace( '[[', '', $section ); $section = str_replace( ']]', '', $section ); - $sectionTitle = wfClone( $title ); - $sectionTitle->mFragment = $section; + if ( $local ) { + $sectionTitle = Title::newFromText( '#' . $section); + } else { + $sectionTitle = wfClone( $title ); + $sectionTitle->mFragment = $section; + } $link = $this->makeKnownLinkObj( $sectionTitle, wfMsg( 'sectionlink' ) ); } $sep='-'; @@ -957,7 +962,7 @@ class Linker { } $comment = preg_replace( $linkRegexp, wfRegexReplacement( $thelink ), $comment, 1 ); } - wfProfileOut( $fname ); + wfProfileOut( __METHOD__ ); return $comment; } @@ -965,19 +970,20 @@ class Linker { * Wrap a comment in standard punctuation and formatting if * it's non-empty, otherwise return empty string. * - * @param $comment String: the comment. - * @param $title Title object. + * @param string $comment + * @param Title $title + * @param bool $local Whether section links should refer to local page * * @return string */ - function commentBlock( $comment, $title = NULL ) { + function commentBlock( $comment, Title $title = NULL, $local = false ) { // '*' used to be the comment inserted by the software way back // in antiquity in case none was provided, here for backwards // compatability, acc. to brion -ævar if( $comment == '' || $comment == '*' ) { return ''; } else { - $formatted = $this->formatComment( $comment, $title ); + $formatted = $this->formatComment( $comment, $title, $local ); return " ($formatted)"; } } @@ -985,12 +991,14 @@ class Linker { /** * Wrap and format the given revision's comment block, if the current * user is allowed to view it. - * @param $rev Revision object. + * + * @param Revision $rev + * @param bool $local Whether section links should refer to local page * @return string HTML */ - function revComment( $rev ) { + function revComment( Revision $rev, $local = false ) { if( $rev->userCan( Revision::DELETED_COMMENT ) ) { - $block = $this->commentBlock( $rev->getRawComment(), $rev->getTitle() ); + $block = $this->commentBlock( $rev->getRawComment(), $rev->getTitle(), $local ); } else { $block = " " . wfMsgHtml( 'rev-deleted-comment' ) . ""; -- 2.20.1